package com.android.rest;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.android.async.GeoNamesAsyncTask;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

public class RESTfulWebServicesActivity extends MapActivity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main);

        // Reset MapView
        MapView map = (MapView) this.findViewById(R.id.map);
        MapController control = map.getController();
        control.setZoom(2);

        // Add dynamic behaviour to Back button
        Button backButton = (Button) this.findViewById(R.id.backButton);
        backButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        });

        // Retrieve matching locations
        GeoNamesAsyncTask task = new GeoNamesAsyncTask(this);
        Intent i = this.getIntent();
        String zipCode = i.getStringExtra(this.getString(R.string.zip));

        if (zipCode == null) {
            zipCode = "24501";
        }

        task.execute(zipCode);

    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}